package com.cj.webapp.account.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cj.webapp.account.pojo.ConstantParamter;
import com.cj.webapp.common.sign.SignVerifyHandle;
import com.cj.webapp.common.utils.MapDetail;
import com.cj.webapp.common.utils.UtilDatetime;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 用户重置交易密码发送报文
 * Created by dell on 2018/1/22.
 */
//@WebServlet(name = "RechargeServlet")
public class MemResetPwdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //HttpSession session = request.getSession();

        SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
        JSONObject jsonhead = new JSONObject(true);
        JSONObject jsonbody = new JSONObject(true);
        jsonbody.put("platfmCustId",MapDetail.resMap.get("platfmCustId").toString());
        jsonbody.put("role",MapDetail.resMap.get("role").toString());

        SignVerifyHandle signVerifyHandle=new SignVerifyHandle();
        String s = signVerifyHandle.signData(ConstantParamter.VIP_NUM, jsonbody.toJSONString());

        // head
        jsonhead.put("serviceName","RESET_PAYWORD");//接口名称
        jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
        jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
        jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
        jsonhead.put("requestNo", "110"+df.format(new Date()));//请求流水(贯穿整个请求返回)
        jsonhead.put("signData",s);
        jsonhead.put("sessionId",MapDetail.resMap.get("sessionId").toString());//sessionId
        jsonhead.put("source",MapDetail.resMap.get("source").toString());//source
        jsonhead.put("token",MapDetail.resMap.get("token").toString());
        jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
        jsonhead.put("rebackUrl",ConstantParamter.HOME_REBACK_Url);//业务处理结果返回url

        request.setAttribute("head",JSON.toJSONString(jsonhead));
        request.setAttribute("body",JSON.toJSONString(jsonbody));
        request.setAttribute("urlString",ConstantParamter.GATE_WAY_URL);

        request.getRequestDispatcher("/page/index/registerPost.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                 doPost(request,response);
    }
}
